//
//  JSMDetailCell.m
//  TakeYouTourTogether
//
//  Created by dllo on 15/12/5.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMDetailCell.h"
#import "JSMDetailsViewController.h"
#import "JSMTouringCell.h"
#import "JSMLeavingHeaderCollectionDetailsViewController.h"
#import "JSMLeavingHotTableViewCell.h"
#import "JSMDreamCitySpecialDetailsViewController.h"
#import "JSMDreamCityPrefectureTrailsDetailsViewController.h"
#import "JSMDreamCityTableViewCell.h"
@interface JSMDetailCell ()<UITableViewDataSource, UITableViewDelegate>

@end

@implementation JSMDetailCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView{
    self.tableView = [[BaseTableView alloc]initWithFrame:self.contentView.frame style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.contentView addSubview:self.tableView];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.num_item == 0) {
        static NSString *reuse = @"saveleaving";
       JSMLeavingHotTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[JSMLeavingHotTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
        [cell.mainImageView sd_setImageWithURL:[NSURL URLWithString:[self.arr[indexPath.row] cover_route_map_cover]] placeholderImage:[UIImage imageNamed:@"placeHolderImage"]];
        cell.titleLabel.text = [self.arr[indexPath.row] name];
        return  cell;

    }else if (self.num_item == 1){
        static NSString *reuse = @"savedreamSpecial";
        JSMDreamCityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[JSMDreamCityTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
        [cell.mainImageView sd_setImageWithURL:[NSURL URLWithString:[self.arr[indexPath.row] imageUrl]] placeholderImage:[UIImage imageNamed:@"placeHolderImage"]];
        cell.titleLabel.text = [self.arr[indexPath.row] name];
        return  cell;

    }else if (self.num_item == 2){
        static NSString *reuse = @"saveDreamPrefecture";
        JSMDreamCityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[JSMDreamCityTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
        [cell.mainImageView sd_setImageWithURL:[NSURL URLWithString:[self.arr[indexPath.row] cover]] placeholderImage:[UIImage imageNamed:@"placeHolderImage"]];
        cell.titleLabel.text = [self.arr[indexPath.row] name];
        return  cell;

    }else if (self.num_item == 3){
        static NSString *reuse = @"saveTouring";
        JSMTouringCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[JSMTouringCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
        [cell.mainImageView sd_setImageWithURL:[NSURL URLWithString:[self.arr[indexPath.row] cover]] placeholderImage:[UIImage imageNamed:@"placeHolderImage"]];
        [cell.userImageView sd_setImageWithURL:[NSURL URLWithString:[[self.arr[indexPath.row] userModel] avatar]] placeholderImage:[UIImage imageNamed:@"placeHolderImage"]];
        cell.titleLabel.text = [self.arr[indexPath.row] name];
        cell.userNameLabel.text = [NSString stringWithFormat:@"%@ · %@ · %@", [[self.arr[indexPath.row] userModel] nickname], [self.arr[indexPath.row] destination], [self.arr[indexPath.row] start_date]];
        return  cell;
        
    }else {
        static NSString *reuse = @"saveStrage";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
        cell.textLabel.text = [self.arr[indexPath.row] name];
        return  cell;
        
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.num_item == 0) {
        JSMLeavingHeaderCollectionDetailsViewController *headerCollectionDetails = [[JSMLeavingHeaderCollectionDetailsViewController alloc] init];
        headerCollectionDetails.hidesBottomBarWhenPushed = YES;
        headerCollectionDetails.showCityModel = self.arr[indexPath.row];
        [self.myDelegate pushVC:headerCollectionDetails];
    }else if (self.num_item == 1){
        JSMDreamCitySpecialDetailsViewController *controller = [[JSMDreamCitySpecialDetailsViewController alloc] init];
        controller.tempModel = self.arr[indexPath.row];
        controller.hidesBottomBarWhenPushed = YES;
        [self.myDelegate pushVC:controller];
    }else if (self.num_item == 2){
        JSMDreamCityPrefectureTrailsDetailsViewController *controller = [[JSMDreamCityPrefectureTrailsDetailsViewController alloc] init];
        controller.tempModel = self.arr[indexPath.row];
        controller.hidesBottomBarWhenPushed = YES;
        [self.myDelegate pushVC:controller];
    }else if (self.num_item == 3){
        JSMDetailsViewController *detaildVc = [[JSMDetailsViewController alloc]init];
        detaildVc.navigationItem.hidesBackButton = YES;
        detaildVc.detailModel = self.arr[indexPath.row];
        detaildVc.str_title = [self.arr[indexPath.row] destination];
        [self.myDelegate pushVC:detaildVc];
    }else if (self.num_item == 4){
        
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200 * ALLEDITIONHEIGHT;
}
- (void)setArr:(NSMutableArray *)arr{
    if (_arr != arr) {
        _arr = [NSMutableArray array];
        _arr = arr;
    }
    [self.tableView reloadData];
}
- (void)setNum_item:(NSInteger)num_item{
    if (_num_item != num_item) {
        _num_item = num_item;
    }
}
@end
